package cn.wolfcode.web.controller;


import cn.wolfcode.domain.MessageReplyDzq;
import cn.wolfcode.service.IMessageReplyDzqService;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ModelAttribute;

@Controller
@RequestMapping("/messageReplyDzq")
public class MessageReplyDzqController {

    @Autowired
    private IMessageReplyDzqService messageReplyDzqService;


    @RequiredPermission(name="留言板回复页面",expression="messageReply:list")
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
        PageInfo<MessageReplyDzq> pageInfo = messageReplyDzqService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "messageReply/list";
    }


    @RequiredPermission(name="留言板回复删除",expression="messageReply:delete")
    @RequestMapping("/delete")
    public String delete(Long id) {
        if (id != null) {
           messageReplyDzqService.delete(id);
        }
        return "redirect:/messageReplyDzq/list";
    }


    @RequiredPermission(name="留言板回复新增/编辑",expression="messageReply:saveOrUpdate")
    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(MessageReplyDzq messageReplyDzq) {
        if (messageReplyDzq.getId() == null) {
            messageReplyDzqService.save(messageReplyDzq);
        } else {
            messageReplyDzqService.update(messageReplyDzq);
        }
        return "redirect:/messageReplyDzq/list";
    }


    @RequiredPermission(name="留言板回复新增/编辑",expression="messageReply:saveOrUpdate")
    @RequestMapping("/input")
    public String input(Long id, Model model) {
        if (id != null) {
            model.addAttribute("messageReply",messageReplyDzqService.get(id));
        }
        return "messageReply/input";
    }
}
